package com.xiaoniu.forum.web.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.xiaoniu.forum.entity.vo.CommunityTopicOptionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.xiaoniu.forum.entity.CommunityTopicCategoryEntity;
import com.xiaoniu.forum.service.CommunityTopicCategoryService;
import com.xiaoniu.forum.common.utils.PageUtils;
import com.xiaoniu.forum.common.utils.R;



/**
 * 话题分类 即Java板块有JavaSE话题分类,Spring话题分类
 *
 * @author xiaoniu
 * @email sunlightcs@gmail.com
 * @date 2021-03-18 14:34:36
 */
@RestController
@RequestMapping("forum/communitytopiccategory")
public class CommunityTopicCategoryController {
    @Autowired
    private CommunityTopicCategoryService communityTopicCategoryService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("forum:communitytopiccategory:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = communityTopicCategoryService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("forum:communitytopiccategory:info")
    public R info(@PathVariable("id") String id){
		CommunityTopicCategoryEntity communityTopicCategory = communityTopicCategoryService.getById(id);

        return R.ok().put("communityTopicCategory", communityTopicCategory);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("forum:communitytopiccategory:save")
    public R save(@RequestBody CommunityTopicCategoryEntity communityTopicCategory){
		communityTopicCategoryService.save(communityTopicCategory);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("forum:communitytopiccategory:update")
    public R update(@RequestBody CommunityTopicCategoryEntity communityTopicCategory){
		communityTopicCategoryService.updateById(communityTopicCategory);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("forum:communitytopiccategory:delete")
    public R delete(@RequestBody String[] ids){
		communityTopicCategoryService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @GetMapping("/option/{communityId}")
    public R getAllWithOptionsByCommunityId(@PathVariable String communityId){
        List<CommunityTopicOptionVo> list =communityTopicCategoryService.getAllWithOptionsByCommunityId(communityId);
        return R.ok().put("data",list);
    }
}
